using UnityEngine;
using System.Collections;

public class ExplosiveBarrel : HittableObject
{
    const float c_ExplosionRadius = 20;
    const float c_ExplosionDamage = 100;
    protected override void OnHittableDestroy()
    {
        m_Active = false;
        Collider[] colliders = Physics.OverlapSphere(this.transform.position, c_ExplosionRadius);
        foreach (Collider c in colliders)
        {
            if (c.transform == this.transform)
            {
                continue;
            }
            Actor a = c.GetComponent<Actor>();
            if (a != null)
            {
                a.OnHit(c_ExplosionDamage, null);
            }
            else
            {
                HittableObject ho = c.GetComponent<HittableObject>();
                if (ho != null)
                {
                    ho.OnHit(c_ExplosionDamage);
                }
                else
                {
                    DestroyHouseQuest dhq = c.GetComponent<DestroyHouseQuest>();
                    if (dhq != null)
                    {
                        dhq.RecieveExplosion();
                    }
                }
            }
        }
        VisionManager.GetInstance().GenerateSound(this.transform.position,c_ExplosionRadius*3);
        GameObject ex = PrefabManager.GetInstance().CreateFromPool("explosion");
        if (ex != null)
        {
           ex.transform.position = this.transform.position;
        }
        SoundManager.Instance.PlaySound("Explosion", this.transform.position, true);
        GameObject.Destroy(this.gameObject);
    }
}
